var t = getApp(),
    a = t.requirejs("core"),
    e = (t.requirejs("jquery"), t.requirejs("foxui"), 0),
    o = t.requirejs("wxParse/wxParse");
Page({
    data: {
        showtab: "groups",
        count_down: !0,
        time: "",
        share: 1,
        options: "",
        show: !1,
        goods_id: 0,
        option_id: 0,
        ladder_id: 0
    },
    onLoad: function(a) {
        this.setData({
            goods_id: !1,
            option_id: !1,
            ladder_id: !1
        })
        t.getCache("isIpx") ? this.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar"
        }) : this.setData({
            isIpx: !1,
            iphonexnavbar: ""
        }), this.setData({
            teamid: a.teamid
        }), this.get_details(a.teamid)
    },
    get_details: function(t) {
        var e = this;
        a.get("groups/team/details", {
            teamid: t
        }, function(t) {
            //t.data.myorder = t.data.orders[0]
            if (0 == t.error && (t.data.goods.content = t.data.goods.content.replace(/data-lazy/g, "src"), e.setData({
                data: t.data,sysset: t.sysset
            }), o.wxParse("wxParseData", "html", t.data.goods.content, e, "0")), 0 == t.data.tuan_first_order.success) {
                if (t.data.lasttime2 <= 0) return void e.setData({
                    count_down: !1
                });
                if (clearInterval(e.data.timer), 0 == t.data.tuan_first_order.success) var a = setInterval(function() {
                    e.countDown(t.data.tuan_first_order.createtime, t.data.tuan_first_order.endtime)
                }, 1e3);
                e.setData({
                    timer: a
                })
            }
        })
    },
    countDown: function(t, a, e) {
        var o = parseInt(Date.now() / 1e3),
            s = parseInt((o < t ? t : a) - o),
            i = Math.floor(s / 86400),
            d = Math.floor((s - 24 * i * 60 * 60) / 3600),
            n = Math.floor((s - 24 * i * 60 * 60 - 3600 * d) / 60),
            r = Math.floor(s - 24 * i * 60 * 60 - 3600 * d - 60 * n);
        0 == i && 0 == d && 0 == n && 0 == r && this.get_details(this.data.teamid);
        var u = [i, d, n, r];
        this.setData({
            time: u
        })
    },

    join_groups: function(params) {
        var d = this,e = params.target.dataset.teamid;
        var s = this.data.data.goods.id
        a.get("groups.goods.goodsCheck", {
            id: s,
            type: "group"
        }, function(res) {
            if(0 == res.error){
                a.get("groups.goods.check_tuan", {
                    id: s,
                    type: "group"
                }, function(r) {
                    if(r.data.order_num <= 0) a.alert("暂无拼团")
                    else{
                        a.get("groups/order/create_order", {
                            id: s,
                            group_option_id: d.data.option_id,
                            ladder_id: d.data.ladder_id,
                            type: "groups",
                            heads: 0,
                            teamid: e
                        }, function(t) {
                            console.log(t)
                            0 == t.error ? wx.navigateTo({
                                url: "../confirm/index?id=" + s + "&heads=0&type=groups&option_id=" + d.data.option_id + "&teamid=" + e + "&ladder_id=" + d.data.ladder_id
                            }) : a.alert(t.message)
                        })
                    }
                })
            }else{
                wx.showToast({
                    title: res.message,
                    icon: "none",
                    duration: 2e3
                })
            }
        });
    },

    onReady: function() {},
    onShow: function() {
        t.checkAuth()
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(t) {
        return {
            title: this.data.data.shopshare.title,
            path: "/pages/groups/groups_detail/index?teamid=" + this.data.data.tuan_first_order.teamid,
            imageUrl: this.data.data.shopshare.imgUrl
        }
    },
    goodsTab: function(t) {
        this.setData({
            showtab: t.target.dataset.tap
        })
    }
});